{extend name="../../../view/public/base" /}

{block name="css"}
<style>
    body {
        background-color: #F2F2F2;
    }
</style>
{/block}

{block name="body"}
<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card" style="padding: 10px">
                <form class="layui-form" lay-filter="addForm" autocomplete="off">
                    <!--名称-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入名称" class="layui-input" value="{$row.name}">
                        </div>
                    </div>
                    <!--文件名-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">文件名</label>
                        <div class="layui-input-block">
                            <input type="text" name="file_name" placeholder="请输入文件名" class="layui-input" value="{$row.file_name}">
                        </div>
                    </div>
                    <!--参数-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">参数</label>
                        <div class="layui-input-block">
                            <input type="text" name="params" placeholder="请输入参数" class="layui-input" value="{$row.params}">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">立即提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<script>
    var layer, form, bwajax, upload, $, laydate;

    layui.use(['layer', 'form', 'bwajax', 'upload', 'laydate'], function () {
        layer = layui.layer;
        form = layui.form;
        bwajax = layui.bwajax.instance();
        upload = layui.upload;
        $ = layui.jquery;
        laydate = layui.laydate;



        //监听提交按钮
        form.on('submit(submitBtn)', function (obj) {
            data = obj.field;

            if(!data.name) {layer.msg('名称不能为空', {icon: 2});return false}
            if(!data.file_name) {layer.msg('文件名不能为空', {icon: 2});return false}
            if(!data.params) {layer.msg('参数不能为空', {icon: 2});return false}


            //ajax调用后台接口
            bwajax.post("{:Url('edit')}?id={$row.id}", data)
                .then(function (response) {
                    if (response.data.data.errcode === 0) {
                        layer.msg('提交成功', {icon: 1});
                        submitSuccess();
                    } else {
                        layer.msg(response.data.msg, {icon: 2});
                    }
                })

            return false;
        })
    });
</script>
{/block}